package com.huobao.yunying.activitys;

import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.yunying.utils.ImageUtils;
import com.huobao.yunying.utils.Utils;
import com.huobao.zhangying.R;

import org.xutils.view.annotation.ViewInject;
/**
 * 通用设置
 * @author Administrator
 *
 */
public class Act_Tongyong extends HuobaoBaseActivity implements OnClickListener{
    
    @ViewInject(R.id.view_clear_cacle)
    private View view_clear_cacle;
    @ViewInject(R.id.tv_huancun)
    private TextView tv_huancun;
    @ViewInject(R.id.view_update)
    private View view_update;
    @ViewInject(R.id.tv_banben)
    private TextView tv_banben;
    @ViewInject(R.id.view_pingfen)
    private View view_pingfen;

	@Override
	protected int getContentView() {
		return R.layout.layout_tongyong;
	}

	@Override
	protected String getTitleText() {
		return "通用";
	}

	@Override
	protected void init() {
		view_clear_cacle.setOnClickListener(this);
		view_update.setOnClickListener(this);
		view_pingfen.setOnClickListener(this);
		tv_huancun.setText(ImageUtils.getCacelSize());
		tv_banben.setText(Utils.getAppVersionName(context));
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()){
		case R.id.view_clear_cacle:
			ImageUtils.clearCache();
			Toast.makeText(context, "缓存清除成功！", Toast.LENGTH_SHORT).show();
			tv_huancun.setText(ImageUtils.getCacelSize());
			break;
		case R.id.view_update:
			checkUpdate();
			break;
		case R.id.view_pingfen:
			Uri uri = Uri.parse("market://details?id="+getPackageName());    
			Intent intent = new Intent(Intent.ACTION_VIEW,uri);    
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);    
			startActivity(intent);    
			break;
		}
	}
	
	private void checkUpdate(){
		Utils.checkUpdate(this,true);
	}

	@Override
	protected boolean getCheckShowMsg() {
		return true;
	}
}
